package edu.hunau.cxb18.spring.annotation.pojo;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.List;
import java.util.Map;

/**
 * @author hb
 * @create 2020-03-11 11:39
 */
@Component("annotation")
@Scope("singleton") //当前的bean为单例
public class AnnotationBean {

    @Value("haoren")
    private String data;
    @Value("#{new java.util.Random().nextInt(100)}")
    private Integer id;
    @Value("#{{'lucy','lily','batman'}}")
    private List<String > lists;
    @Value("#{{'key1':'value1','key2':'value2'} }")
    private Map<String,String> maps;


    @Override
    public String toString() {
        return "AnnotationBean{" +
                "data='" + data + '\'' +
                ", id=" + id +
                ", lists=" + lists +
                ", maps=" + maps +
                '}';
    }

    @PostConstruct
    public void init(){
        System.out.println("初始化方法");
    }

    @PreDestroy
    public void destory(){
        System.out.println("自定义销毁的方法");
    }
}
